package com.example.administrator.myservice;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import java.sql.Time;

/*需要利用Binder 和connetion进行连接*/
public class MyService extends Service {
    private MyBinder binder;
    private boolean isLive=true;
    @Override
    public IBinder onBind(Intent intent) {
        Log.e("MyService","onBind");
        return binder;
    }

    @Override
    public void onCreate() {
        Log.e("MyService","onCreate");
        binder=new MyBinder();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (isLive){
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Log.e("MyService","time="+ System.currentTimeMillis());
                }
            }
        }).start();
        super.onCreate();
    }

    private String getTimestr() {

        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("MyService","onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        isLive=false;
        Log.e("MyService","onDestroy");
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {

        Log.e("MyService","onUnbind");
        return super.onUnbind(intent);
    }
}
